<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="协商议事"></uni-navbar></view>

		<view class="container">
			<view class="banner"><map class="map" id="map" :longitude="longitude" :latitude="latitude" scale="14"></map></view>
			<u-row class="link-box" gutter="0" align="top">
				<u-col span="3" v-if="$sysMenus('xsys_tijiao')">
					<navigator hover-class="none" class="link-item" url="/pagesA/assembly/add">
						<image src="/static/img/icon_26.png" mode="aspectFill"></image>
						提交议题
					</navigator>
				</u-col>
				<u-col span="3">
					<navigator hover-class="none" class="link-item" url="/pagesA/assembly/list">
						<image src="/static/img/icon_25.png" mode="aspectFill"></image>
						议题查询
					</navigator>
				</u-col>
				<u-col span="3">
					<navigator hover-class="none" class="link-item" url="/pagesA/assembly/list?topic=2">
						<image src="/static/img/icon_24.png" mode="aspectFill"></image>
						议题初审
					</navigator>
				</u-col>
				<u-col span="3">
					<navigator hover-class="none" class="link-item" url="/pagesA/assembly/list?topic=6">
						<image src="/static/img/icon_27.png" mode="aspectFill"></image>
						协商议题
					</navigator>
				</u-col>
			</u-row>

			<view class="list-box">
				<view class="filter-inner">
					<view class="filter-btn" :class="filterType == 0 ? 'active' : ''" @click="type(0)">
						<image src="/static/img/icon_33.png" mode="widthFix"></image>
						<image src="/static/img/icon_33_f.png" mode="widthFix"></image>
						协商议题
					</view>
					<view class="filter-btn" :class="filterType == 1 ? 'active' : ''" @click="type(1)">
						<image src="/static/img/icon_32.png" mode="widthFix"></image>
						<image src="/static/img/icon_32_f.png" mode="widthFix"></image>
						规则制度
					</view>
				</view>

				<view class="list-info_02" v-for="(item, index) of assemblyList" :key="index" @click="navTo(item)">
					<view class="left">
						<view class="info-title">{{ item.title }}</view>
						<view class="info-btm">{{ item.createTime | parseTime('{y}-{m}-{d}') }}</view>
					</view>
					<view class="right" :class="[index % 2 == 0 ? 'bg1' : 'bg2']">有事好商量</view>
				</view>
				<u-loadmore :status="loading" />
			</view>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			filterType: 0,
			keyword: '',
			region: '',
			flag_new: '1',
			latitude: 36.400266,
			longitude: 118.879228,
			assemblyList: [],

			assembly: {
				title: '',
				clientCode: ''
			},
			loading: 'loadmore'
		};
	},
	onReady() {
		uni.getLocation({
			type: 'wgs84',
			success: res => {
				this.longitude = res.longitude;
				this.latitude = res.latitude;
			}
		});
	},
	onLoad() {
		this.loadLogin();
		this.loadData();
	},
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.sysUser) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.assembly.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
				this.region = this.userInfo.sysUser.remark2;
				this.roleCodes = this.userInfo.roleCodes.join(',');

				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}
			let url = '/xieshangyishi/info/list';
			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				keyword: this.keyword,
				clientCode: this.clientCode,
				region: this.region,
				roleCodes: this.roleCodes,
				flag_new: this.flag_new,
				userId: this.userId,
				discussTopicInfo: this.assembly
			};
			if (this.filterType == 1) {
				url = '/xieshangyishi/resm/list';
				data = {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					keyword: this.keyword,
					clientCode: this.clientCode,
					userId: this.userId,
					resm: this.assembly
				};
			} else if (this.$roleCodes('xsys_meeting_room')) {
				data.flag_new = '6';
			} else if (this.$roleCodes('xsys_info')) {
				data.flag_new = '0';
			}
			this.$request(url, data, {
				load: true
			}).then(res => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.assemblyList = [];
				}
				try {
					this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
					this.pageNum = this.pageNum + 1;
					this.assemblyList = this.assemblyList.concat(res.data.records);
				} catch (e) {
					this.loading = 'nomore';
				}
				this.loaded = true;
				if (this.assemblyList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		search(e) {
			this.keyword = e;
			this.assembly.title = e;
			this.loadData('refresh');
		},
		type(e) {
			this.filterType = e;
			this.loadData('refresh');
		},
		navTo(item) {
			if (this.filterType == 1) {
				uni.navigateTo({
					url: '/pagesA/assembly/resm_detail?id=' + item.id
				});
			} else {
				uni.navigateTo({
					url: '/pagesA/assembly/detail?id=' + item.id
				});
			}
		}
	}
};
</script>

<style lang="scss">
.list-box {
	margin-bottom: 30rpx;
	padding: 30rpx 30rpx 0;
	border-radius: 30rpx;
	background-color: #fff;
}
.list-info_02 .right {
	&.bg1 {
		background-image: url($staticUrl+'/static/img/xieshangyishi1.png');
	}
	&.bg2 {
		background-image: url($staticUrl+'/static/img/xieshangyishi2.png');
	}
}
</style>
